package com.pen.changgou.user.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.pen.changgou.user.entity.Address;
import com.pen.changgou.user.service.AddressService;
import com.pen.changgou.common.core.utils.R;



/**
 * 
 *
 * @author yaodao
 * @Date 2020-11-29 22:19:49
 */
@Api(tags = " 管理")
@RestController
@RequestMapping("user/address")
public class AddressController {
    @Autowired
    private AddressService addressService;

    /**
     * 通过ID查询菜单的详细信息
     * @param id 菜单ID
     * @return 菜单详细信息
     */
    @GetMapping("/{id}")
    public R getById(@PathVariable Long id) {
        return R.ok(addressService.getById(id));
    }

    /**
     * 列表
     */
    @ApiOperation("分页查询(排序)")
    @GetMapping("/page")
    public R<Page> pge( Page page,Address address) {
        return R.ok( addressService.page(page,Wrappers.query(address)));

    }

    @ApiOperation("分页查询(排序)")
    @GetMapping("/list")
    public R<List<Address>> list( Map<String,Object> param) {
        return R.ok(addressService.list(new QueryWrapper<>()));

    }
    /**
     * 信息
     */
    @ApiOperation("详情查询")
    @GetMapping("/info/{id}")

    public R<Address> info(@PathVariable("id") Integer id){
		Address address = addressService.getById(id);

        return R.ok(address);
    }

    /**
     * 保存
     */
    @ApiOperation("保存")
    @PostMapping("/save")

    public R<Object> save(@RequestBody Address address){
		addressService.save(address);

        return R.ok(null);
    }

    /**
     * 修改
     */
    @ApiOperation("修改")
    @PostMapping("/update")
    public R<Object> update(@RequestBody Address
        address){
		addressService.updateById(address);

        return R.ok(null);
    }

    /**
     * 删除
     */
    @ApiOperation("删除")
    @PostMapping("/delete")
    public R<Object> delete(@RequestBody Integer[] ids){
		addressService.removeByIds(Arrays.asList(ids));

        return R.ok(null);
    }

}
